package com.pig4cloud.pigx.storage.controller;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import com.pig4cloud.pigx.storage.entity.BaseStoreGroupEntity;
import com.pig4cloud.pigx.storage.service.BaseStoreGroupService;
import org.springframework.security.access.prepost.PreAuthorize;
import com.pig4cloud.pigx.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * 仓库组
 *
 * @author jiangjs
 * @date 2024-01-20 00:12:26
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/storeGroup" )
@Tag(description = "baseStoreGroup" , name = "仓库组管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class BaseStoreGroupController {

    private final  BaseStoreGroupService baseStoreGroupService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param baseStoreGroup 仓库组
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('storage_baseStoreGroup_view')" )
    public R getBaseStoreGroupPage(@ParameterObject Page page, @ParameterObject BaseStoreGroupEntity baseStoreGroup) {
        LambdaQueryWrapper<BaseStoreGroupEntity> wrapper = Wrappers.lambdaQuery();
        return R.ok(baseStoreGroupService.page(page, wrapper));
    }


    /**
     * 通过id查询仓库组
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('storage_baseStoreGroup_view')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(baseStoreGroupService.getById(id));
    }

    /**
     * 新增仓库组
     * @param baseStoreGroup 仓库组
     * @return R
     */
    @Operation(summary = "新增仓库组" , description = "新增仓库组" )
    @SysLog("新增仓库组" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('storage_baseStoreGroup_add')" )
    public R save(@RequestBody BaseStoreGroupEntity baseStoreGroup) {
        return R.ok(baseStoreGroupService.save(baseStoreGroup));
    }

    /**
     * 修改仓库组
     * @param baseStoreGroup 仓库组
     * @return R
     */
    @Operation(summary = "修改仓库组" , description = "修改仓库组" )
    @SysLog("修改仓库组" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('storage_baseStoreGroup_edit')" )
    public R updateById(@RequestBody BaseStoreGroupEntity baseStoreGroup) {
        return R.ok(baseStoreGroupService.updateById(baseStoreGroup));
    }

    /**
     * 通过id删除仓库组
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除仓库组" , description = "通过id删除仓库组" )
    @SysLog("通过id删除仓库组" )
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('storage_baseStoreGroup_del')" )
    public R removeById(@RequestBody Long[] ids) {
        return R.ok(baseStoreGroupService.removeBatchByIds(CollUtil.toList(ids)));
    }


}